package com.cskaoyan.market.config;

import com.cskaoyan.market.db.domain.MarketSystem;
import com.cskaoyan.market.db.domain.MarketSystemExample;
import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.db.mapper.MarketSystemMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SystemConfig {

    @Autowired
    MarketSystemMapper marketSystemMapper;

    // 先通过配置管理的小程序配置拿到小程序首页的显示数量
    private Integer brandCount;
    private Integer catalogList;
    private Integer catalogGoods;
    private Integer hotGoodsCount;
    private Integer newGoodsCount;
    private Integer topicCount;

    public void init() {
        MarketSystemExample marketSystemExample = new MarketSystemExample();
        List<MarketSystem> marketSystemList = marketSystemMapper.selectByExample(marketSystemExample);
        for (MarketSystem marketSystem : marketSystemList) {
            if ("market_wx_index_brand".equals(marketSystem.getKeyName())) {
                brandCount = Integer.parseInt(marketSystem.getKeyValue());
            } else if ("market_wx_catlog_list".equals(marketSystem.getKeyName())) {
                catalogList = Integer.parseInt(marketSystem.getKeyValue());
            } else if ("market_wx_catlog_goods".equals(marketSystem.getKeyName())) {
                catalogGoods = Integer.parseInt(marketSystem.getKeyValue());
            } else if ("market_wx_index_hot".equals(marketSystem.getKeyName())) {
                hotGoodsCount = Integer.parseInt(marketSystem.getKeyValue());
            } else if ("market_wx_index_new".equals(marketSystem.getKeyName())) {
                newGoodsCount = Integer.parseInt(marketSystem.getKeyValue());
            } else if ("market_wx_index_topic".equals(marketSystem.getKeyName())) {
                topicCount = Integer.parseInt(marketSystem.getKeyValue());
            }
        }
    }
}
